import sys,os

if len(sys.argv)<3:
    print 'Usage: python delNotExist.py old.lst notExist'
    exit(1)

fi=open(sys.argv[2],'r')
dele=set()
for line in fi:
    line=line.strip()
    if len(line)<1:
    	continue
    dele.add(line)
    os.system('rm bed/'+line+'.bed')
fi.close()
fi=open(sys.argv[1],'r')
fo=open('bed.lst','w')
for line in fi:
    line=line.strip()
    if len(line)<1 or line.split('\t')[0] in dele:
    	continue
    fo.write(line+'\n')
fi.close()
fo.close()    	
